LDFLAGS += -lcommon_sdk


PLAYER_LIBS := $(patsubst %,%.so,$(PLAYERS))

all: $(REFEREE).so  $(PLAYER_LIBS)
	
	
$(foreach d,$(PLAYERS),$(eval $(d).so: $(patsubst %.c,%.o,$(wildcard $(d)*.c)))) #Add .c dependencies
$(foreach d,$(PLAYERS),$(eval $(d).so: $(patsubst %.cpp,%.o,$(wildcard $(d)*.cpp)))) #Add .cpp dependencies


$(REFEREE).so: $(REFEREE_OBJ)  $(TOP_DIR)/src/libcommon_sdk.a 
	$(CXX) -shared  -o $@ $(REFEREE_OBJ) $(LDFLAGS)

lib$(PROXY).a: $(PROXY_OBJ)
	ar rc $@ $^
	ranlib $@

$(PLAYER_LIBS):  $(TOP_DIR)/src/libcommon_sdk.a lib$(PROXY).a 
	$(CXX) -d -shared -L. -o $@ $(patsubst %.a, ,$^) -Wl,-whole-archive lib$(PROXY).a -Wl,-no-whole-archive $(LDFLAGS) 

clean:
	rm -rf *.so *.o *.a

$(TOP_DIR)/src/libcommon_sdk.a:
	make -C $(TOP_DIR) common_sdk

.PHONY: all clean 
